package promote.brozen.algorithm.hwod;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Stream;

/**
 * @author Brozen
 * @date 2020/9/12 2:50 PM
 * @email brozen@qq.com
 */
public class SaySeven {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int[] nums = Stream.of(line.split(" ")).mapToInt(Integer::valueOf).toArray();

        int max = -1;
        Map<Integer, Integer> count = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int c = count.computeIfAbsent(nums[i], kk -> 0) + 1;
            count.put(nums[i], c);

            if (nums[i] > max) {
                max = nums[i];
            }
        }

        int num = 0;
        int index = 0;
        int iterMax = 0;
        int[] originNums = new int[nums.length];
        for(;;) {
            num++;
            if (num % 7 == 0
                    || num % 10 == 7
                    || (num / 10) % 10 == 7
                    || (num / 100) % 10 == 7) {
                originNums[index]++;
                iterMax = iterMax < originNums[index] ? originNums[index] : iterMax;
            }

            if (index + 1 >= originNums.length) {
                index = 0;
            } else {
                index++;
            }

            if (iterMax >= max && check(new HashMap<Integer, Integer>(count), originNums)) {
                break;
            }
        }

        for (int n : originNums) {
            System.out.printf(n + " ");
        }
    }

    private static boolean check(HashMap<Integer,Integer> count, int[] originNums) {
        for (int n : originNums) {
            if (!count.containsKey(n)) {
                return false;
            } else {
                Integer c = count.get(n);
                if (c > 1) {
                    count.put(n, c-1);
                } else if (c == 1) {
                    count.remove(n);
                } else {
                    return false;
                }
            }
        }

        return true;
    }

}
